package com.shop2cn.iapi.agentproducts.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.agentproducts.parameter.AddAgentProductBean;
import com.shop2cn.iapi.agentproducts.parameter.GetSharePosterBean;
import com.shop2cn.iapi.agentproducts.service.GetSharePosterCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P2;
import com.ymttest.business.service.AddAgentProductCallService;
import com.ymttest.utils.AgentUsers;

/**
 * 获取商品分享海报 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_GetSharePoster {
	private static GetSharePosterBean getshareposterBean;
	private static GetSharePosterCall getshareposterCall;
	private static int sellerId = AgentUsers.rootUserId;
	private static String sellerName = "NickautoTest";

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取商品分享海报");
	}

	@Before
	public void caseUp() {
		getshareposterBean = new GetSharePosterBean();
		getshareposterCall = new GetSharePosterCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getshareposterCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category({ P1.class })
	@TestCase
	@Ignore
	public void Tc_GetSharePoster_001() {
		Logger.start(true, "正确商品id，与商户id，成功");
		try {
//			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(sellerId,
//					sellerName, false);
//			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
//			Thread.sleep(5000);
			getshareposterBean.setUserId(500146002);
			getshareposterBean.setProductId("p2296222");
			getshareposterCall.setData(getshareposterBean);
			getshareposterCall.setData(getshareposterBean);
			getshareposterCall.callService();
			Logger.verifyEquals("200", getshareposterCall.getJsonObject().get("code").getAsString(), "验证Code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_GetSharePoster_002() {
		Logger.start(true, "商品id为空，失败");
		try {
			getshareposterBean.setUserId(sellerId);
			getshareposterCall.setData(getshareposterBean);
			getshareposterCall.callService();
			getshareposterCall.callService();
			Logger.verifyEquals("400", getshareposterCall.getJsonObject().get("code").getAsString(), "验证Code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_GetSharePoster_003() {
		Logger.start(true, "商户id为空，失败");
		try {
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(sellerId,
					sellerName, false);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			Thread.sleep(5000);
			getshareposterBean.setProductId(productId);
			getshareposterCall.setData(getshareposterBean);
			getshareposterCall.callService();
			Logger.verifyEquals("400", getshareposterCall.getJsonObject().get("code").getAsString(), "验证Code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_GetSharePoster_004() {
		Logger.start(true, "删除商品，获取失败");
		try {
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(sellerId,
					sellerName, false);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			Thread.sleep(5000);
			AddAgentProductCallService.DeleteProduct(productId, sellerId);
			Thread.sleep(5000);
			getshareposterBean.setUserId(sellerId);
			getshareposterBean.setProductId(productId);
			getshareposterCall.setData(getshareposterBean);
			getshareposterCall.callService();
			Logger.verifyEquals("201", getshareposterCall.getJsonObject().get("code").getAsString(), "验证Code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_GetSharePoster_005() {
		Logger.start(true, "获取成功后，删除商品，再次获取，失败");
		try {
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(sellerId,
					sellerName, false);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			Thread.sleep(5000);
			getshareposterBean.setUserId(sellerId);
			getshareposterBean.setProductId(productId);
			getshareposterCall.setData(getshareposterBean);
			getshareposterCall.callService();
			Logger.verifyEquals("200", getshareposterCall.getJsonObject().get("code").getAsString(), "验证Code");

			AddAgentProductCallService.DeleteProduct(productId, sellerId);

			Thread.sleep(5000);
			getshareposterBean.setUserId(sellerId);
			getshareposterBean.setProductId(productId);
			getshareposterCall.setData(getshareposterBean);
			getshareposterCall.callService();
			Logger.verifyEquals("201", getshareposterCall.getJsonObject().get("code").getAsString(), "验证Code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}